package com.shuql.cloud.oauth2.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 产品接口测试类
 *
 * @author ：shuquanliang
 * @date ：Created in 2020/4/23 11:38
 * @description：
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @GetMapping("/list")
    //@PreAuthorize("hasAnyAuthority('product:list')") //验证权限
    public List list(HttpServletRequest request) {
        String principal = (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<String> list = new ArrayList<>();
        list.add("眼镜");
        list.add("格子衬衣");
        list.add("双肩包");
        list.add(principal);

        System.out.println("X-SHUQL-USERNAME:" + request.getHeader("X-SHUQL-USERNAME"));
        System.out.println("X-SHUQL-TOKEN:" + request.getHeader("X-SHUQL-TOKEN"));

        return list;
    }

}
